/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmCadastroProfessor.java
 *
 * Created on 21/09/2009, 17:56:08
 */

package professor.telas;

import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import professor.classes.Professor;
import professor.bd.ProfessorDAO;

/**
 *
 * @author Gabi
 */
public class FrmCadastroProfessor extends javax.swing.JFrame {

    /** Creates new form FrmCadastroProfessor */
    public FrmCadastroProfessor(Professor professor) {
        initComponents();
        setLocationRelativeTo(null);
        setVisible(true);
        try {
            professorDAO = new ProfessorDAO();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
            ex.printStackTrace();
        }
        this.professor = professor;
        populaTela();
        }
    private void populaTela() {
        nomeProfessorjTextField.setText(professor.getNome());
        residencialjFormattedTextField.setText(professor.getFoneFixo());
        celularjFormattedTextField.setText(professor.getFoneCelular());
        emailjTextField.setText(professor.getEmail());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cadastroProfessorjPanel = new javax.swing.JPanel();
        nomeProfessorjLabel = new javax.swing.JLabel();
        nomeProfessorjTextField = new javax.swing.JTextField();
        residencialjLabel = new javax.swing.JLabel();
        residencialjFormattedTextField = new javax.swing.JFormattedTextField();
        celularjLabel = new javax.swing.JLabel();
        celularjFormattedTextField = new javax.swing.JFormattedTextField();
        residencialIconjLabel = new javax.swing.JLabel();
        celularIconjLabel = new javax.swing.JLabel();
        emailjLabel = new javax.swing.JLabel();
        emailIconjLabel = new javax.swing.JLabel();
        emailjTextField = new javax.swing.JTextField();
        painelBotoesjPanel = new javax.swing.JPanel();
        salvarTelajButton = new javax.swing.JButton();
        fecharTelajButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Professores");
        setLocationByPlatform(true);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cadastroProfessorjPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        URL url = this.getClass().getResource("/imagens/logo_mini.png");
        Image imagemTitulo = Toolkit.getDefaultToolkit().getImage(url);
        this.setIconImage(imagemTitulo);
        try{
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
        }catch (Exception e){
            e.printStackTrace();
        }
        cadastroProfessorjPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        nomeProfessorjLabel.setText("Nome do Professor");
        cadastroProfessorjPanel.add(nomeProfessorjLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 23, -1, -1));
        cadastroProfessorjPanel.add(nomeProfessorjTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 250, -1));

        residencialjLabel.setText("Residencial");
        cadastroProfessorjPanel.add(residencialjLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 73, -1, -1));

        try {
            residencialjFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        cadastroProfessorjPanel.add(residencialjFormattedTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 90, 100, -1));

        celularjLabel.setText("Celular");
        cadastroProfessorjPanel.add(celularjLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(188, 73, -1, -1));

        try {
            celularjFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        cadastroProfessorjPanel.add(celularjFormattedTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 90, 100, -1));

        residencialIconjLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/telephone.png"))); // NOI18N
        cadastroProfessorjPanel.add(residencialIconjLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, -1, -1));

        celularIconjLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/phone.png"))); // NOI18N
        cadastroProfessorjPanel.add(celularIconjLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 70, -1, -1));

        emailjLabel.setText("E-mail");
        cadastroProfessorjPanel.add(emailjLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 123, -1, -1));

        emailIconjLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/email.png"))); // NOI18N
        cadastroProfessorjPanel.add(emailIconjLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 122, -1, -1));
        cadastroProfessorjPanel.add(emailjTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 250, -1));

        painelBotoesjPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        painelBotoesjPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        salvarTelajButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/tick.png"))); // NOI18N
        salvarTelajButton.setText("Salvar");
        salvarTelajButton.setToolTipText("Salvar");
        salvarTelajButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarTelajButtonActionPerformed(evt);
            }
        });
        painelBotoesjPanel.add(salvarTelajButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 8, -1, -1));

        fecharTelajButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/cross.png"))); // NOI18N
        fecharTelajButton.setText("Fechar");
        fecharTelajButton.setToolTipText("Fechar");
        fecharTelajButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fecharTelajButton(evt);
            }
        });
        painelBotoesjPanel.add(fecharTelajButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 7, -1, -1));

        cadastroProfessorjPanel.add(painelBotoesjPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 180, 250, 40));

        getContentPane().add(cadastroProfessorjPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 290, 250));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fecharTelajButton(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fecharTelajButton
        // refresh lista de consulta de professores. Perguntar codido para Julio;
        this.dispose();
}//GEN-LAST:event_fecharTelajButton
    private void salvarTelajButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarTelajButtonActionPerformed
        this.professor.setNome(nomeProfessorjTextField.getText());
        this.professor.setFoneFixo(residencialjFormattedTextField.getText());
        this.professor.setFoneCelular(celularjFormattedTextField.getText());
        this.professor.setEmail(emailjTextField.getText());
        try{
        professorDAO.salvar(professor);
        JOptionPane.showMessageDialog(this,"Dados salvos com sucesso");
        }catch (Exception ex){
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this,"Dados não foram salvos");
        }
    }//GEN-LAST:event_salvarTelajButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel cadastroProfessorjPanel;
    private javax.swing.JLabel celularIconjLabel;
    private javax.swing.JFormattedTextField celularjFormattedTextField;
    private javax.swing.JLabel celularjLabel;
    private javax.swing.JLabel emailIconjLabel;
    private javax.swing.JLabel emailjLabel;
    private javax.swing.JTextField emailjTextField;
    private javax.swing.JButton fecharTelajButton;
    private javax.swing.JLabel nomeProfessorjLabel;
    private javax.swing.JTextField nomeProfessorjTextField;
    private javax.swing.JPanel painelBotoesjPanel;
    private javax.swing.JLabel residencialIconjLabel;
    private javax.swing.JFormattedTextField residencialjFormattedTextField;
    private javax.swing.JLabel residencialjLabel;
    private javax.swing.JButton salvarTelajButton;
    // End of variables declaration//GEN-END:variables
    private ProfessorDAO professorDAO;
    private Professor professor;
}
